﻿@using Digital.WCFClient.ConfigService
@using System.Collections.ObjectModel
@using Digital.Common.Mvc.Extensions
@using Digital.Web.Controllers
@using Microsoft.AspNet.Identity
@using Digital.Common.Utilities
@model Digital.WCFClient.ConfigService.NewsModel
@{
    ViewBag.Title = "添加播报";
    Layout = "~/Views/Shared/_LayoutDigital.cshtml";
}
@section PageSpecificJavascriptIncludes{
    <link rel="stylesheet" href="../DigitalStyle/css/jquery.gritter.css" />
    <link rel="stylesheet" href="../DigitalStyle/css/bootstrap-fileupload.min.css" />
    <link rel="stylesheet" href="../DigitalStyle/css/jquery.tagsinput.css" />
    <link rel="stylesheet" href="../DigitalStyle/css/colorpicker.css" />

    <script src="../DigitalStyle/js/jquery.gritter.min.js"></script>
    <script src="../DigitalStyle/js/bootstrap-fileupload.min.js"></script>
    <script src="../DigitalStyle/js/jquery.validate.js"></script>
    <script src="../DigitalStyle/js/JqueryToken.js"></script>
    <script src="../DigitalStyle/js/jquery.autogrow-textarea.js"></script>
    <script src="../DigitalStyle/js/messages_cn.js"></script>
    <!-- CKEditor -->
    <script src="../DigitalStyle/js/ckeditor/ckeditor.js"></script>
    <script src="../DigitalStyle/js/ckeditor/adapters/jquery.js"></script>

    <!-- commom form js -->
    <script src="../DigitalStyle/js/jquery.tagsinput.min.js"></script>
    <script src="../DigitalStyle/js/jquery.maskedinput.min.js"></script>
    <script src="../DigitalStyle/js/colorpicker.js"></script>
    <script type="text/javascript" src="@Url.StaticFile("/DigitalStyle/js/flashupload.js")"></script>
    <script src="../DigitalStyle/js/formvalidator.js"></script>

}

<div class="pageheader">
    <h2><i class="fa fa-user"></i> 添加播报 <span>播报中心</span></h2>
    <div class="breadcrumb-wrapper">
        <span class="label">你的位置:</span>
        <ol class="breadcrumb">
            <li><a href="">企业中心</a></li>
            <li class="active">播报中心</li>
        </ol>
    </div>
</div>

<div class="contentpanel">
    <div class="row">

        <div class="col-sm-12">
            <div class="panel panel-info">
                <div class="panel-heading">
                    <div class="panel-btns">
                        <a href="" class="minimize">&minus;</a>
                    </div><!-- panel-btns -->
                    <h3 class="panel-title">播报管理</h3>
                </div>


                <div class="panel-body panel-body-nopadding">
                    <form class="form-horizontal form-bordered" id="firstForm" onsubmit="return false;">
                        @Html.AntiForgeryToken()
                        <div class="form-group">
                            <label class="col-sm-3 control-label"><span class="asterisk">*</span> 文章标题</label>
                            <div class="col-sm-4">
                                @Html.TextBoxFor(m => m.NewsTitle, new { @class = "form-control" })
                                @Html.ValidationMessageFor(m => m.NewsTitle, null, new { @class = "help-inline" })
                                @*<input id="NewsTitle" value="@Model.NewsTitle" type="text" placeholder="" class="form-control" />*@
                                @*<span class="errorMsg"></span>*@
                            </div>
                        </div>

                        <div class="form-group">
                            <label class="col-sm-3 control-label"><span class="asterisk">*</span> 摘要</label>
                            <div class="col-sm-6">
                                @Html.TextAreaFor(m => m.NewsAbstract, new { @class = "form-control",@rows="5" })
                                @Html.ValidationMessageFor(m => m.NewsAbstract, null, new { @class="help-inline"})
                                @*<textarea id="NewsAbstract" class="form-control" rows="3">@Model.NewsAbstract</textarea>*@
                                <span class="help-block">
                                    (限制100字以内)
                                </span>
                            </div>
                        </div>

                        <div class="form-group">
                            <label class="col-sm-3 control-label"><span class="asterisk">*</span> 文章缩略图</label>
                            <div class="col-sm-6">
                                <div class="fileupload fileupload-new" data-provides="fileupload" id="container">
                                    <div class="input-append">
                                        <div class="uneditable-input">
                                            <i class="glyphicon glyphicon-file fileupload-exists"></i>
                                            <span id="filelist" class="fileupload-preview"></span>
                                        </div>
                                        <span class="btn btn-default btn-file">
                                            <span class="fileupload-new">选择文章缩略图</span>
                                            <span class="fileupload-exists">更改</span>
                                            @*<input id="pickfiles" value="@Model.NewsThumbnail" type="file" />*@
                                            @Html.TextBoxFor(m => m.NewsThumbnail, new { @id = "pickfiles", @type = "file" })
                                            @Html.ValidationMessageFor(m => m.NewsThumbnail, null, new { @class="help-inline"})
                                        </span>
                                        <a href="#" id="uploadfiles" class="btn btn-default">上传</a>
                                    </div>
                                </div>
                                <input id="ImagePath" type="hidden" value="@Model.NewsThumbnail" />
                                <img id="PersonImage" src="@Html.IsNull(Model.NewsThumbnail, "../DigitalStyle/images/pic-none.png", Model.NewsThumbnail)" class="thumbnail img-responsive" alt="" />

                            </div>
                        </div>


                        <div class="form-group">
                            <label class="col-sm-3 control-label"><span class="asterisk">*</span> 发布日期</label>
                            <div class="col-sm-4 ">
                                <div class="input-group">
                                    @*<input type="text" value="@Model.ReleaseTime" class="form-control" placeholder="mm/dd/yyyy" id="ReleaseTime" />*@
                                    @Html.TextBoxFor(m => m.ReleaseTime, new { @class="form-control",@placeholder="mm/dd/yyyy"})
                                    @Html.ValidationMessageFor(m => m.ReleaseTime, null, new { @class="help-inline"})
                                    <span class="input-group-addon"><i class="glyphicon glyphicon-calendar"></i></span>
                                </div>
                            </div>
                        </div>

                        <div class="form-group">
                            <label class="col-sm-3 control-label"><span class="asterisk">*</span> 所属分类</label>

                            <div class="col-sm-4 ">
                                <select id="NewsCategory" class="form-control chosen-select" data-placeholder="选择分类..." required>
                                </select>
                                @Html.ValidationMessage("NewsCategory", new { @class = "help-inline" })
                                <a href="/Company/CompanyNewsClassManage" class="btn btn-default">添加分类</a>
                            </div>
                        </div>

                        <div class="form-group">
                            <label class="col-sm-3 control-label">文章排序值</label>
                            <div class="col-sm-4">
                                <input id="NewsOrderID" value="@Model.NewsOrderID" type="text" placeholder="数字、越小越靠前" class="form-control" />
                            </div>
                        </div>

                        <div class="form-group">
                            <label class="col-sm-3 control-label"><span class="asterisk">*</span> 关键字</label>
                            <div class="col-sm-4">
                                @*<input name="NewsKeywords" id="NewsKeywords" class="form-control" value="@Model.NewsKeywords" />*@
                                @Html.TextBoxFor(m => m.NewsKeywords, new { @class = "form-control" })
                                @Html.ValidationMessageFor(m => m.NewsKeywords, null, new { @class="help-inline"})
                            </div>
                        </div>


                        <div class="form-group">
                            <label class="col-sm-3 control-label">标签</label>
                            <div class="col-sm-4">
                                <input name="NewsLabels" id="NewsLabels" class="form-control" value="@Model.NewsLabels" />
                            </div>
                        </div>



                        <div class="form-group">
                            <label class="col-sm-3 control-label" for="checkbox"><span class="asterisk">*</span> 文章内容</label>
                            <div class="col-sm-6">
                                @*<textarea id="NewsBody" name="NewsBody" placeholder="请在此输入文章内容" cols="80" rows="10">@Model.NewsBody</textarea>*@
                                @Html.TextAreaFor(m => m.NewsBody, new {@placeholder = "请在此输入文章内容", @cols = "80", @rows = "10" })
                                @Html.ValidationMessageFor(m => m.NewsBody, null, new { @class="help-inline"})
                            </div>
                        </div>

                        <div class="panel-footer">
                            <div class="row">
                                <div class="col-sm-6 col-sm-offset-3">
                                    <button id="btnSubmit" class="btn btn-primary" onclick="javascript:Save();">提交</button>&nbsp;
                                    <button class="btn btn-default" onclick="javascript: location.reload();">取消</button>
                                </div>
                            </div>
                        </div>

                    </form>
                </div>

            </div><!-- panel -->
        </div>



    </div>
</div>



<script>

    function callback(msg)
    {
        $("#ImagePath").val(msg.msg.url);
        $("#PersonImage")[0].src = msg.msg.url;
    }
    jQuery(document).ready(function () {

        $('#UploadButton').FileUpload({
            'subfolder': 'UserInfo' + '@Digital.Common.CryptoService.MD5Encrypt(User.Identity.GetUserId(),Digital.Common.SerurityType.UserInfoFolder)',
            'ImageId': '',
        });
        //select option : NewsCategory
        var NewsCategoryjsons=@Html.Raw(Newtonsoft.Json.JsonConvert.SerializeObject((List<BaseNameValueMode>)ViewBag.CategoryList))
        DropOption(NewsCategoryjsons,$("#NewsCategory"),@Model.NewsCategoryID);

        // Chosen Select
        jQuery(".chosen-select").chosen({ 'width': '100%', 'white-space': 'nowrap' });

        // Tags Input
        jQuery('#NewsLabels').tagsInput({ width: 'auto' });

        // Tags Input
        jQuery('#NewsKeywords').tagsInput({ width: 'auto' });

        // Textarea Autogrow
        jQuery('#NewsAbstract').autogrow();

        // Color Picker
        if (jQuery('#colorpicker').length > 0) {
            jQuery('#colorSelector').ColorPicker({
                onShow: function (colpkr) {
                    jQuery(colpkr).fadeIn(500);
                    return false;
                },
                onHide: function (colpkr) {
                    jQuery(colpkr).fadeOut(500);
                    return false;
                },
                onChange: function (hsb, hex, rgb) {
                    jQuery('#colorSelector span').css('backgroundColor', '#' + hex);
                    jQuery('#colorpicker').val('#' + hex);
                }
            });
        }

        // Date Picker
        jQuery('#ReleaseTime').datepicker();

        jQuery('#ReleaseTime-inline').datepicker();

        jQuery('#ReleaseTime-multiple').datepicker({
            numberOfMonths: 3,
            showButtonPanel: true
        });



    });
</script>
<script>
    jQuery(document).ready(function () {
        // With Form Validation Wizard
        jQuery("#firstForm").validate({
            rules:{
                NewsTitle:{
                    required:true,
                    isContainsSpecialChar:true
                },
                NewsAbstract:{
                    required:true,
                    stringContentCheck:[1,200]
                },
                NewsThumbnail:{
                    required:true
                },
                ReleaseTime:{
                    required:true
                },
                NewsCategory:{
                    required:"#NewsCategory option:selected"
                },
                NewsKeywords:{
                    required:true,
                    isContainsSpecialChar:true
                },
                NewsBody:{
                    required:true
                }
            },
            messages:{
                NewsTitle:{
                    required:"请输入文章标题",
                    isContainsSpecialChar:"含有中英文特殊字符"
                },
                NewsAbstract:{
                    required:"请输入文章摘要",
                    stringContentCheck:$.validator.format("请确保内容输入{0}-{1}字节以内")
                },
                NewsThumbnail:{
                    required:"请选择文章缩略图"
                },
                ReleaseTime:{
                    required:"请选择文章发布日期"
                },
                NewsKeywords:{
                    required:"请输入文章关键字",
                    isContainsSpecialChar:"含有中英文特殊字符"
                },
                NewsCategory:{
                    required:"请选择文章分类"
                },
                NewsBody:{
                    required:"请输入文章内容"
                }
            },
            highlight: function (element) {
                jQuery(element).closest('.form-group').removeClass('has-success').addClass('has-error');
            },
            success: function (element) {
                jQuery(element).closest('.form-group').removeClass('has-error');
            },
            focusInvalid: false,
            onkeyup: false,
            ignore:'',
            errorPlacement: function (error, element) {
                //alert(error.html());
                error.insertAfter($(element).parent().children().last());
            }
        });

        // CKEditor
        jQuery('textarea#NewsBody').ckeditor();
        jQuery('#inlineedit1, #inlineedit2').ckeditor();

        CKEDITOR.instances["NewsBody"].on("instanceReady", function()   
        {   
            //set keyup event   
            this.document.on("keyup", updateTextArea);   
            //and paste event   
            this.document.on("paste", updateTextArea);   
  
        });
    });

    function updateTextArea()   
    {   
        CKEDITOR.tools.setTimeout( function()   
        {    
            $("#NewsBody").val(CKEDITOR.instances[$("#NewsBody").attr("id")].getData());   
            $("#NewsBody").trigger('keyup');  
            $("#NewsBody").trigger('paste');
        }, 0);     
    } 

    // For News Add Operation , Submit Button
    function Save() {
        var $valid = jQuery("#firstForm").valid();
        //debugger;
        if (!$valid) {
            return false;
        }
        else {


            var NewsID = 0; // default option : insert new company model
            @{
                var Ids = Request["Id"] == null ? "0" : Request["Id"].ToString();
            }
            var IsInsert=@Ids;
            //------------------TAB 01 : 播报信息
            var valNewsTitle = $.jsparams.input("NewsTitle");
            var valNewsAbstract = $.jsparams.input("NewsAbstract");
            var valNewsThumbnail = $.jsparams.input("ImagePath");
            var valNewsCategoryID = $.jsparams.select("NewsCategory");
            var valNewsOrderID = $.jsparams.input("NewsOrderID");
            var valNewsKeywords = $.jsparams.input("NewsKeywords");
            var valNewsLabels = $.jsparams.input("NewsLabels");
            var valNewsBody = $.jsparams.textarea("NewsBody");//$("#NewsBody").val();//CKEDITOR.instances['NewsBody'].getData();


            //alert(stringTABONE);

            var datas={Id:IsInsert,NewsTitle:valNewsTitle,NewsAbstract:valNewsAbstract,
                NewsThumbnail:valNewsThumbnail,NewsCategoryID:valNewsCategoryID,NewsOrderID:valNewsOrderID,
                NewsKeywords:valNewsKeywords,NewsLabels:valNewsLabels,NewsBody:valNewsBody};
            ComAjax("/Company/CompanyNewsSave",datas,"播报信息");

        }
    }

</script>


